package util;

import java.util.Date;
import java.text.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2001-2004</p>
 * <p>Company: </p>
 * @author Keith Shie
 * @version 1.0
 */

public class MultipleDateFormat extends DateFormat {

	private DateFormat[] dateFmts;

  public MultipleDateFormat() {
		dateFmts = new DateFormat[0];
  }

  public MultipleDateFormat( DateFormat[] fmts) {
		dateFmts = fmts;
  }

  public Date parse( String source, ParsePosition pos ) {
		int i = 0;
		Date dt = null;

		while ( dt == null && i < dateFmts.length ){
			dt = dateFmts[ i ].parse( source, pos );
			i++;
		}

		return dt;
  }

  public StringBuffer format( Date date, StringBuffer toAppendTo,
														  FieldPosition fieldPosition ) {
		if ( dateFmts.length > 0 ){
			dateFmts[ 0 ].format( date, toAppendTo, fieldPosition );
		}

		return toAppendTo;
  }
}